import Vue from 'vue';

/* 如果用了meri-design请注释这一句 */
// import 'less/main';

import Jstracker from 'jstracker';
import { Loading } from 'meri-design';
import GetTimeNow from 'GetTimeNow';

import router from './router';
import store from './store';
import App from './App';

const isDev = process.env.NODE_ENV === 'development';
Vue.config.productionTip = isDev;

/**
 * 全局的异常处理拦截
 * type类型如下
 * var ERROR_RUNTIME = 1
 * var ERROR_SCRIPT = 2
 * var ERROR_STYLE = 3
 * var ERROR_IMAGE = 4
 * var ERROR_AUDIO = 5
 * var ERROR_VIDEO = 6
 * var ERROR_CONSOLE = 7
 * var ERROR_TRY_CATCH = 8
 *
 * TODO 后期应该配合后端传递，目前是保存localstorage中
 */
Jstracker.init({
    report(errorLogs) {
        console.table(errorLogs);
        const errObj = errorLogs.map(d => {
            d.message = d.desc.message;
            d.stack = d.desc.stack;
            return d;
        });
        localStorage.setItem(`Jstracker-ERROR-${GetTimeNow()}`, JSON.stringify(errObj));
    }
});

// 注册首屏加载
const loading = Loading();
// 注册首屏加载关闭函数，***需要手动调用***
// Vue.prototype.$removeLoading = () => {
//     Loading.close(loading);
// };
document.onreadystatechange = () => {
    if (document.readyState === 'complete') Loading.close(loading);
};

new Vue({
    router,
    store,
    render: (h) => h(App)
}).$mount('#persagy');
